<template>
  <div class="down-container">
    <!-- Tips  -->
    <marquee>
      <!-- <i class="iconfont icon-gonggao1"></i>
      <span class="tips-color">{{tips}}</span> -->
    </marquee>

    <!-- 文库吧tip-->
    <div class="login-box">
      <div class="login-title">
        <p class="iconfont icon-wenkuba"></p>
      </div>
      <div class="login-title-bottom"></div>
    </div>

    <!-- 下载 -->
    <el-form class="down-box" :model="dataForm" :rules="dataRule" ref="dataForm">
      <el-form-item prop="dwnUrl">
        <el-input placeholder="http://www..." clearable prefix-icon="el-icon-search" v-model="dataForm.dwnUrl">
        </el-input>
      </el-form-item>


      <p class="alink">
        <a :href="gourl" @click="goTaobao()" target="_blank" style="color:#FF295B;">新账号购买 请点击
        </a>
      </p>

      <el-button class="mui-btn-block lgoin-btn" @click="dataFormSubmit()">
        <i class=" iconfont icon-xiazai"></i>下载文档</el-button>
    </el-form>
    <remote-js src="http://pv.sohu.com/cityjson?ie=utf-8"></remote-js>
  </div>
</template>
<script>
  import {
    isURL
  } from "@/utils/validate";
  import {
    Toast
  } from 'mint-ui';
  export default {
    data() {
      var validateisURL = (rule, value, callback) => {
        if (!isURL(value)) {
          callback(new Error("输入的文档链接地址格式错误"));
        } else {
          callback();
        }
      };
      return {
        // tips: '我是滚动的小文字',       //公告提示
        // iftips: false,
        dataForm: {
          dwnUrl: "",
          anShopUrl: '',
          titleMessage: '下载记录保留最近两个月.严禁账号共享,机器下载,违者封禁账号.问题反馈QQ群754324373', //百度文库官网正在维护中 目前暂时下载不了 维护完成第一时间开放下载 请稍后尝试
          myUrl: '',
          wenkuxiaUrl: ''
        },
        gourl: '',
        dataRule: {
          dwnUrl: [{
              required: true,
              message: "文档链接地址不能为空",
              trigger: "blur"
            },
            {
              validator: validateisURL,
              trigger: "blur"
            }
          ]
        }
      }
    },
    created() {
      this.getDetails()
      if (this.tips != '') {
        this.iftips = true
      }
      
    },
    components: {

      'remote-js': {
        render(createElement) {
          return createElement('script', {
            attrs: {
              type: 'text/javascript',
              src: this.src
            }
          });
        },
        props: {
          src: {
            type: String,
            required: true
          },
        },
      },
    },
    methods: {
      // down
      dataFormSubmit() {
        this.$refs.dataForm.validate(valid => {
          if (valid) {
            this.$indicator.open();
            this.$http({
              url: this.$http.adornUrl(`/app/dwn`),
              method: "post",
              data: this.$http.adornData({
                dwnUrl: this.dataForm.dwnUrl
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$indicator.close();
                this.dataForm.dwnUrl = "";
                Toast('下载成功')
                window.location.href = data.dwnUrl;
              } else {
                Toast(data.msg);
              }
            }).catch((error) => {
              this.$indicator.close();
              Toast('请求失败,请重试')
            });


          }
        });
      },
      getRandomInt: function (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min
      },
      goTaobao() {
        var cname = returnCitySN['cname'];
        //默认的淘宝地址
       
        var defalutUrl =
          'https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.25911debSaAzUa&ft=t&id=605148708976';
        if (cname.indexOf("广州") >= 0) {
          if (this.dataForm.anShopUrl !== undefined && this.dataForm.anShopUrl !== '') {
            this.gourl = this.dataForm.anShopUrl
          } else {
            this.gourl = defalutUrl;
          }

        } else if (cname.indexOf("湖南") >= 0) {
          if (this.dataForm.anShopUrl !== undefined && this.dataForm.anShopUrl !== '') {
            this.gourl = this.dataForm.anShopUrl
          } else {
            this.gourl = defalutUrl;
          }
        } else {

          if (this.dataForm.myUrl !== undefined && this.dataForm.myUrl !== '') {
           
            var random = this.getRandomInt(1, 100)
            if (random % 2 == 0) {
              this.gourl = this.dataForm.myUrl
            } else {
              this.gourl = this.dataForm.wenkuxiaUrl;
            }
          } else {
           
            this.gourl = this.dataForm.wenkuxiaUrl

          }

        }

      },
      getDetails() {
        this.$http({
          url: this.$http.adornUrl('/app/getMessageInfo'),
          method: 'post',
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
 
            this.dataForm.anShopUrl = data.anShopUrl
            this.dataForm.wenkuxiaUrl = data.wenkuxiaUrl;
            this.dataForm.titleMessage = data.titleMessage;
            this.dataForm.myUrl = data.myUrl;
          }
        }).catch((error) => {

        });
      },

    }
  }

</script>
<style lang="less">
  .down-container {
    line-height: 70px;

    .marquee {
      visibility: hidden;
      background-color: pink;
      line-height: 40px;
    }

    .icon-gonggao1 {
      color: black;
      text-align: center;
      margin-right: 5px;
    }

    .tips-color {
      color: black;
    }

    .login-box {
      width: 280px;
      margin: 0 auto;
      margin-top: 60px;

      .login-title {
        width: 280px;
        height: 105px;
        border: 2px solid white;
        border-bottom: none;
        text-align: center;

        p {
          font-size: 44px;
          color: white;
          letter-spacing: 4px;
          margin: 0px;
          line-height: 105px;
        }

        &::after {
          width: 320px;
          content: "一 输入文档链接地址即可快速下载文档 一";
          display: block;
          color: white;
          font-size: 14px;
          letter-spacing: 2px;
          text-align: center;
          margin-left: -20px;
          line-height: 21px;
        }
      }

      .login-title-bottom {
        width: 280px;
        height: 28px;
        border: 2px solid white;
        margin-top: 21px;
        border-top: none;
      }
    }

    .down-box {
      text-align: center;

      p {
        font-size: 14px;
        color: #999999;
      }

      a {
        color: #16c79d;
        text-decoration: underline;
      }

      .alink {
        margin-top: 20px;

        a {
          font-size: 16px;
          letter-spacing: 2px;
        }
      }

      .el-input {
        margin-top: 37px;
        width: 100%;

        .el-icon-search {
          font-size: 16px;
          color: white;
        }

        .el-input__clear {
          font-size: 16px;
          color: #ffffff;
        }

        .el-input__inner {
          color: white;
          background: rgba(255, 255, 255, 0.3);

          &::-webkit-input-placeholder {
            color: white;
          }
        }
      }

      .mui-btn-block {
        padding: 0px;
        font-size: 14px;
        color: #16c79d;
        letter-spacing: 2px;
        text-align: center;
      }

      .el-button {
        margin-top: 16px;
        width: 132px;
        text-align: center;
        line-height: 32px;

        .icon-xiazai {
          font-size: 18px;
          margin-right: 12px;
        }
      }
    }
  }

</style>
